/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ove.openmath.jome.formaters.mml;

/**
 *
 * @author Mr.Sam
 */
import fr.ove.utils.*;
import fr.ove.openmath.jome.model.*;
import fr.ove.openmath.jome.formaters.mml.*;

/**
* Formats the formula tree structure as its corresponding MathML object.<BR>
* This is the formater of operators which have "classical" MathML format :<BR>
* <apply><BR>
*   <an operator/><BR>
*   ... lots of other things ...<BR>
* </apply><BR>
*
* @author © 2000 DIRAT Laurent
* @version 1.0 23/05/2000
*/
public class ClassicalOperatorFormater implements Formater {
    /**
    * Returns the specified object formatted as a string.
    * @param formatedObject the formatted object (for structured object, could represents the beginning).
    * @param formaterRepository where the different other formaters are.
    * @param obj the object to format.
    */
    public String format(String formatedObject, FormaterRepository formaterRepository, Object obj) {
        MathMLFormater mmlFormater = (MathMLFormater) formaterRepository;
        FormulaTreeStructure fts = (FormulaTreeStructure) obj;
        
        FormulaTreeStructure ftsChild;
        Formater formater;
        
        String objectId = fts.getResourceIdentifier();
        
        formatedObject += mmlFormater.writeStartApplication();
        formatedObject += mmlFormater.writeSymbol(objectId);
        
        int nbChildren = fts.getNbChildren();
        for (int i = 0; i < nbChildren; i++) {
            ftsChild = (FormulaTreeStructure) ((FormulaTreeStructure) obj).getChild(i);
            objectId = ftsChild.getResourceIdentifier();
            formater = formaterRepository.getFormater(objectId);
            formatedObject = formater.format(formatedObject, formaterRepository, ftsChild);
        }
        formatedObject += mmlFormater.writeEndApplication();
        
        return formatedObject;
    }
}